package com.hk.employeemanagementsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hk.employeemanagementsystem.mapper.UserEntityMapper;
import com.hk.employeemanagementsystem.entity.UserEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author by 何坤
 * @Classname SecurityService
 * @Description TODO
 * @Date 2019/12/4 22:01
 */
@Service
public class SecurityService implements UserDetailsService {

    private Logger logger = LoggerFactory.getLogger(SecurityService.class);

    @Resource
    private UserEntityMapper userEntityMapper;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        UserEntity userEntitiesByPhone = userEntityMapper.getUserByPhone(s);
        if (userEntitiesByPhone == null) {
            throw new UsernameNotFoundException("用户"+ s +"不存在!!!");
        }
        return userEntitiesByPhone;
    }
}
